package com.lmc.controller;

import com.lmc.common.LogInfo;
import com.lmc.common.R;
import com.lmc.pojo.Order;
import com.lmc.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class OrderController {

    @Autowired
    OrderService orderService;

    /**
     * 消费接口
     * @param order
     * @return
     */
    @LogInfo(describe = "操作用户", modelName = "消费")
    @PostMapping("/spend")
    public R spendMoney(@RequestBody Order order) {
        if (order.getAmount() != null) {
            R<String> msg = orderService.spendMoney(order);
            return R.success(msg);
        }
        return R.error("操作失败!");
    }

    /**
     * 退款接口
     * @param order
     * @return
     */
    @LogInfo(describe = "操作用户", modelName = "退款")
    @PostMapping("/refund")
    public R refundMoney(@RequestBody Order order) {
        if (order.getAmount() != null) {
            R<String> msg = orderService.refundMoney(order);
            return R.success(msg);
        }
        return R.error("操作失败");
    }


}
